The present invention relates to computer graphics, and more particularly to interactive graphics systems such as home video game platforms. Still more particularly, this invention relates to techniques for generating shadows using full scene shadow mapping in a low cost graphics system, and to use of graphics pipeline texture coordinate generation and/or texture mapping arrangements to generate precision numerical values supporting shadow comparisons and other effects.
Many of us have seen films containing remarkably realistic dinosaurs, aliens, animated toys and other fanciful creatures. Such animations are made possible by computer graphics. Using such techniques, a computer graphics artist can specify how each object should look and how it should change in appearance over time, and a computer then models the objects and displays them on a display such as your television or a computer screen. The computer takes care of performing the many tasks required to make sure that each part of the displayed image is colored and shaped just right based on the position and orientation of each object in a scene, the direction in which light seems to strike each object, the surface texture of each object, and other factors.
Because computer graphics generation is complex, computer-generated three-dimensional graphics just a few years ago were mostly limited to expensive specialized flight simulators, high-end graphics workstations and supercomputers. The public saw some of the images generated by these computer systems in movies and expensive television advertisements, but most of us couldn""t actually interact with the computers doing the graphics generation. All this has changed with the availability of relatively inexpensive 3D graphics platforms such as, for example, the Nintendo 64(copyright) and various 3D graphics cards now available for personal computers. It is now possible to interact with exciting 3D animations and simulations on relatively inexpensive computer graphics systems in your home or office.
Shadows are important for creating realistic images and providing the viewer with visual cues about where objects appear relative to one another. Many different shadowing techniques are known. See, for example, Woo et al., xe2x80x9cA Survey of Shadow Algorithms,xe2x80x9d IEEE Computer Graphics and Applications, Volume 10, Number 6, pages 13-32 (November 1990).
A problem graphics system designers confronted in the past was how to draw shadows using low cost graphics systems. One known technique for accomplishing this is called shadow mapping. This technique allows a common z-buffer-based renderer to be used to generate shadows quickly on arbitrary objects. See Williams xe2x80x9cCasting Curved Shadows on Curved Surfaces,xe2x80x9d Computer Graphics (SIGGRAPH ""78 Proceedings), Volume 12, Number 3, pages 270-274 (August 1978). Using this technique, the graphics system renders the scene using the z-buffer algorithm with respect to the position and direction of the light source. For each pixel in the z buffer, the resulting rendered z depth contains the distance to the object that is closest to the light source. This depth map is called a shadow map. The scene is then rendered a second time, but this time with respect to the viewer (camera). As each drawing primitive is being rendered, its location (depth from the light) is compared to the shadow map. If a rendered point is further away from the light source than the value in the shadow map, that point is in shadow and its brightness is attenuated. If the rendered point is closer to the light source than the shadow map value, the point is illuminated by the light and is not in shadow.
One efficient way to implement this shadow mapping technique is by exploiting texture mapping hardware to project the shadow map into the scene. See, e.g., Heidrich et al., xe2x80x9cApplications of Pixel Textures in Visualization and Realistic Image Synthesis,xe2x80x9d Proceedings 1999 Symposium On Interactive 3D Graphics, pages 127-134 (April 1999); Segal et al., xe2x80x9cFast Shadows and Lighting Effects Using Texture Mapping,xe2x80x9d Computer Graphics (SIGGRAPH ""92 Proceedings, Volume 26, Number 2, pages 249-252 (July 1992). Using these techniques, the shadow map can be generated using z buffering (that is, lighting, texturing and the writing of color values into the color buffer can be turned off). Then, the scene is rendered from the viewer using only ambient lighting to resolve visibility. A shadow testing step is then performed to compare the z value in the z buffer with the z value (which is transformed from the coordinate system of the light source into the coordinate system of the viewer) in the shadow map. One technique is to set an additional value in the frame buffer for each pixel based on the result of the shadow comparison at that pixel. The whole scene is then rendered using the entire lighting equationxe2x80x94with the final color of each pixel being the color from the ambient lighting pass plus the color from the full rendering pass multiplied by the additional value in the frame buffer.
An extension of Williams"" shadow mapping technique proposed by Wang et al., xe2x80x9cSecond-Depth Shadow Mappingxe2x80x9d (Department of Computer Science, University of North Carolina at Chapel Hill) solves certain self-shadowing problems (where a surface may cast a shadow onto itself due to lack of precision in the shadow comparison) by performing the shadow comparison based on the depth of a second surface defined by a primitive. Wang et al thus suggest using front-faced culling techniques to eliminate the first surface of primitives when generating the shadow map. This prevents limited precision depth comparisons from causing front surfaces to cast shadows upon themselves.
The above-described shadow mapping techniques allow general-purpose graphics hardware to render arbitrary shadows. However, using these techniques, the quality of the shadow produced depends on the resolution (in pixels) of the shadow map, and also on the numerical precision of the z buffer and the depth comparison. See Moller et al., Real-Time Rendering, pages 179-183 (AK Peters Ltd., 1999). Achieving adequate numerical precision for the depth comparison can be a problem for low cost graphics systems such as video game platforms. In full scene shadowing, any object can cast a shadow on any object (including itself). The number of bits of information used to encode the distance value will determine where the near and far planes can be on the projection from the light source, and how much depth complexity can be provided in the rendered shadow map. To find out whether a surface is in shadow or outside of shadow, a depth comparison is performed between the actual distance from the light to the surface being rendered, and the nearest distance from the light (determined by rendering the scene from the light source into the shadow map). The number of bits in this distance value will determine the range that a particular light can cast shadows into the scene. The lower the precision, the less depth complexity that can be provided on the shadows and on the light. Hence, lower precision can limit the number of shadows the light can cast into the scene and how far ranging those shadows can be.
If the graphics pipeline does not provide sufficient numerical precision for shadow mapping effects, higher precision depth values can usually be obtained by having the graphics system host processor perform necessary calculations under software control. However, this places substantial additional loading on the host processor, and may make it difficult or impossible to render full-scene shadows in real time within the context of an interactive animated computer graphics system that allows the user to change the position(s) of one or more objects within the scene at will.
Another way to get around the limited precision problem is to use a form of shadow mapping which does not attempt the shadow depth comparison, but works instead by identifying what is seen by the light. See, e.g., Hourcade et al, xe2x80x9cAlgorithms for Antialiased Cast Shadowsxe2x80x9d, Computers and Graphics, vol. 9, no. 3, pp. 259-265 (1985). If an object is seen from the selected viewpoint and the shadow map indicates that the object is also seen by the light, then the object is illuminated. This technique has the advantage of avoiding the shadow depth comparison. However, areas where objects or polygons meet can be problematic. It is possible to resolve such problem areas by using different identifiers for different objectsxe2x80x94although an object with a single identifier can never cast a shadow upon itself using this algorithm.
While much work has been done in the past, further improvements are possible.
The present invention solves the numerical precision problem while providing techniques and arrangements that perform full scene shadow mapping using low cost, limited precision hardware such as that found, for example, in home video game platforms and personal computer graphics accelerators.
One aspect of the invention uses a texture coordinate generator to assist in calculating distance between light position and a primitive surface at a precision that is based on the dynamic depth of the scene. A texture mapper uses the generated texture coordinates to look up a precision distance value from a ramp function stored as a texture. The resulting precision distance value can be compared with the corresponding depth value in the shadow map to determine whether or not the pixel is in shadow.
In one embodiment, the ramp function is stored as a 2-D texture in such a way that certain texels are redundant and not all texels are used. To eliminate lookup errors, redundant texel values are provided where the ramp function crosses texel row/column boundaries.